package cn.monkey.chat.server.connect;

import cn.monkey.state.core.reactive.SimpleReactiveStateGroupPool;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Component
public class ShutDownHookRunner implements ApplicationRunner {

    private final SimpleReactiveStateGroupPool stateGroupPool;

    public ShutDownHookRunner(SimpleReactiveStateGroupPool stateGroupPool) {
        this.stateGroupPool = stateGroupPool;
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        Runtime.getRuntime().addShutdownHook(new Thread(stateGroupPool::refresh));
    }
}
